package com.pinc.cpbl;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TableRow;

public class main extends Activity {

	private TableRow but_game1;
	private TableRow but_game0;
	private TableRow but_game2;
	private TableRow but_rank;
	private TableRow but_bgrade;
	private TableRow but_pgrade;
	private TableRow but_setting;
	private TableRow but_about;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_table_view);

		but_rank = (TableRow) this.findViewById(R.id.tableRow6);
		but_bgrade = (TableRow) this.findViewById(R.id.tableRow10);
		but_pgrade = (TableRow) this.findViewById(R.id.tableRow11);
		but_game1 = (TableRow) this.findViewById(R.id.tableRow2);
		but_game0 = (TableRow) this.findViewById(R.id.tableRow3);
		but_game2 = (TableRow) this.findViewById(R.id.tableRow4);
		but_setting = (TableRow) this.findViewById(R.id.tableRow8);
		but_about = (TableRow) this.findViewById(R.id.tableRow9);

		Intent i = new Intent(this, BroadcastService.class);
		startService(i);

		but_rank.setOnClickListener(new generalClickListener(show_rank.class));
		but_game1.setOnClickListener(new integerClickListener(show_game.class, "day", 1));
		but_game0.setOnClickListener(new integerClickListener(show_game.class, "day", 0));
		but_game2.setOnClickListener(new integerClickListener(show_game.class, "day", 2));

		but_setting.setOnClickListener(new generalClickListener(set_settings.class));

		but_about.setOnClickListener(new generalClickListener(show_about.class));
		
		but_bgrade.setOnClickListener(new integerClickListener(show_grade.class, "category", 0));
		but_pgrade.setOnClickListener(new integerClickListener(show_grade.class, "category", 1));
	}

	private class integerClickListener implements View.OnClickListener
	{
		@SuppressWarnings("rawtypes")
		private Class which_class;
		private String tag;
		private int value;

		@SuppressWarnings("rawtypes")
		public integerClickListener(Class c, String tag, int value) {
			this.which_class = c;
			this.tag = tag;
			this.value = value;
		}

		@Override
		public void onClick(View v) {
			Bundle bd = new Bundle();
			Intent intent = new Intent(main.this, which_class);
			bd.putInt(tag, value);
			intent.putExtras(bd);
			startActivity(intent);
		}
	}
	
	private class generalClickListener implements View.OnClickListener
	{
		@SuppressWarnings("rawtypes")
		private Class which_class;

		@SuppressWarnings("rawtypes")
		public generalClickListener(Class c) {
			this.which_class = c;
		}

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(main.this, which_class);
			startActivity(intent);
		}
	}
}